package com.fire.controller;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fire.bo.title.req.TitleReq;
import com.fire.bo.title.res.TitleRes;
import com.fire.common.RspObjBean;
import com.fire.service.TitleService;
import com.fire.util.BussinessUtils;
import com.fire.util.ErrRsp;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Controller
@CrossOrigin
@RequestMapping("/pc/title")
@Api(value = "标题图片", description = "标题图片")
public class TitleController
{
	@Autowired
	private TitleService titleService;
	
	@ApiOperation(value = "修改标题图片", notes = "修改标题图片")
    @RequestMapping(value = "/updateTitle", method = RequestMethod.POST)
    public @ResponseBody RspObjBean updateTitle(@RequestBody @Valid TitleReq beans, BindingResult bindingResult)
    {
        // 非空验证
        if (bindingResult.hasErrors())
        {
            return BussinessUtils.rspErrorHeadInfo(ErrRsp.PARAM_NULL_CODE, bindingResult.getFieldError().getDefaultMessage());
        }

        try
        {
        	titleService.updateTitle(beans);
            // 根据上级类别key得到类别集合
            return BussinessUtils.rspErrorHeadInfo(ErrRsp.SUCCESS_CODE, ErrRsp.SUCCESS_CODE_DESC, null);
        }
        catch (Exception e)
        {
        	e.printStackTrace();
            return BussinessUtils.rspErrorHeadInfo(ErrRsp.SYSTEM_ERROR_CODE, ErrRsp.SYSTEM_ERROR_DESC);
        }
    }
	
	
//	@ApiOperation(value = "标题图片查询", notes = "标题图片查询", response = TitleRes.class)
//    @RequestMapping(value = "/findTitle", method = RequestMethod.POST)
//    public @ResponseBody RspObjBean findTitle(BindingResult bindingResult)
//    {
//        try
//        {
//        	TitleRes info = titleService.findTitle();
//            // 根据上级类别key得到类别集合
//            return BussinessUtils.rspErrorHeadInfo(ErrRsp.SUCCESS_CODE, ErrRsp.SUCCESS_CODE_DESC, info);
//        }
//        catch (Exception e)
//        {
//        	e.printStackTrace();
//            return BussinessUtils.rspErrorHeadInfo(ErrRsp.SYSTEM_ERROR_CODE, ErrRsp.SYSTEM_ERROR_DESC);
//        }
//    }
	
	@ApiOperation(value = "标题图片查询", notes = "标题图片查询",response = TitleRes.class)
	@RequestMapping(value = "/findTitle", method = RequestMethod.POST)
	public @ResponseBody RspObjBean findTitle(
			 )
	{
		
		try
		{
			TitleRes info = titleService.findTitle();
			// 根据上级类别key得到类别集合
			return BussinessUtils.rspErrorHeadInfo(ErrRsp.SUCCESS_CODE,
					ErrRsp.SUCCESS_CODE_DESC, info);
		}
		catch (Exception e)
		{
			e.printStackTrace();
			return BussinessUtils.rspErrorHeadInfo(ErrRsp.SYSTEM_ERROR_CODE,
					ErrRsp.SYSTEM_ERROR_DESC);
		}
	}
	
}
